import 'package:dailoz/entity/tag_entity.dart';
import 'package:dailoz/views/task_tag_detail.dart';
import 'package:dailoz/widgets/label_type.dart';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';

class ProfilePageService {
  static List<Widget> generateTagList(
      BuildContext context, List<dynamic>? tagList) {
    List<Widget> widgetList = [];
    if (tagList!.isNotEmpty) {
      for (Map<String, dynamic> tag in tagList) {
        TagEntity tagEntity = TagEntity.fromJson(tag);
        widgetList.add(LabelType(
          labelName: tagEntity.tagContent,
          taskNum: tagEntity.total,
          labelColor: const Color.fromRGBO(133, 143, 233, 0.25),
          childPadding: const EdgeInsets.all(10.0),
          onTap: () {
            onTap(context, tagEntity.tagContent);
          },
          child: Container(
            width: 48.0,
            height: 48.0,
            decoration: const BoxDecoration(
              color: Color(0xff858fe9),
              borderRadius: BorderRadius.all(
                Radius.circular(14.0),
              ),
            ),
            child: const Icon(
              Icons.person_outline,
              color: Colors.white,
            ),
          ),
        ));
      }
    }
    return widgetList;
  }

  static void onTap(BuildContext context, String tagContent) async {
    final prefs = await SharedPreferences.getInstance();
    await prefs.setString("tag-name", tagContent);
    // ignore: use_build_context_synchronously
    Navigator.pushNamed(context, TaskTagDetail.id, arguments: tagContent);
  }
}
